
<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Datatables</title>

    <!-- Main Styles -->
    <link rel="stylesheet" href="../../static/styles/style.min.css">

    <!-- Material Design Icon -->
    <link rel="stylesheet" href="../../static/fonts/material-design/css/materialdesignicons.css">

    <!-- mCustomScrollbar -->
    <link rel="stylesheet" href="../../static/plugin/mCustomScrollbar/jquery.mCustomScrollbar.min.css">

    <!-- Waves Effect -->
    <link rel="stylesheet" href="../../static/plugin/waves/waves.min.css">

    <!-- Sweet Alert -->
    <link rel="stylesheet" href="../../static/plugin/sweet-alert/sweetalert.css">

    <!-- Data Tables -->
    <link rel="stylesheet" href="../../static/plugin/datatables/media/css/dataTables.bootstrap.min.css">
    <link rel="stylesheet" href="../../static/plugin/datatables/extensions/Responsive/css/responsive.bootstrap.min.css">

    <!-- Dark Themes -->
<!--    <link rel="stylesheet" href="../../static/styles/style-black.min.css">-->
</head>

<body>
<div id="page1">
</div>
<!-- /.main-menu -->


<!-- /.fixed-navbar -->

<div id="notification-popup" class="notice-popup js__toggle" data-space="75">
    <h2 class="popup-title">Your Notifications</h2>
    <!-- /.popup-title -->
    <div class="content">
        <ul class="notice-list">
            <li>
                <a href="#">
                    <span class="avatar"><img src="../../static/images/avatar-sm-1.jpg" alt=""></span>
                    <span class="name">John Doe</span>
                    <span class="desc">Like your post: “Contact Form 7 Multi-Step”</span>
                    <span class="time">10 min</span>
                </a>
            </li>
            <li>
                <a href="#">
                    <span class="avatar"><img src="../../static/images/avatar-sm-2.jpg" alt=""></span>
                    <span class="name">Anna William</span>
                    <span class="desc">Like your post: “Facebook Messenger”</span>
                    <span class="time">15 min</span>
                </a>
            </li>
            <li>
                <a href="#">
                    <span class="avatar bg-warning"><i class="fa fa-warning"></i></span>
                    <span class="name">Update Status</span>
                    <span class="desc">Failed to get available update data. To ensure the please contact us.</span>
                    <span class="time">30 min</span>
                </a>
            </li>
            <li>
                <a href="#">
                    <span class="avatar"><img src="../../static/images/avatar-1.jpg" alt=""></span>
                    <span class="name">Jennifer</span>
                    <span class="desc">Like your post: “Contact Form 7 Multi-Step”</span>
                    <span class="time">45 min</span>
                </a>
            </li>
            <li>
                <a href="#">
                    <span class="avatar"><img src="../../static/images/avatar-sm-6.jpg" alt=""></span>
                    <span class="name">Michael Zenaty</span>
                    <span class="desc">Like your post: “Contact Form 7 Multi-Step”</span>
                    <span class="time">50 min</span>
                </a>
            </li>
            <li>
                <a href="#">
                    <span class="avatar"><img src="../../static/images/avatar-sm-4.jpg" alt=""></span>
                    <span class="name">Simon</span>
                    <span class="desc">Like your post: “Facebook Messenger”</span>
                    <span class="time">1 hour</span>
                </a>
            </li>
            <li>
                <a href="#">
                    <span class="avatar bg-violet"><i class="fa fa-flag"></i></span>
                    <span class="name">Account Contact Change</span>
                    <span class="desc">A contact detail associated with your account has been changed.</span>
                    <span class="time">2 hours</span>
                </a>
            </li>
            <li>
                <a href="#">
                    <span class="avatar"><img src="../../static/images/avatar-sm-7.jpg" alt=""></span>
                    <span class="name">Helen 987</span>
                    <span class="desc">Like your post: “Facebook Messenger”</span>
                    <span class="time">Yesterday</span>
                </a>
            </li>
            <li>
                <a href="#">
                    <span class="avatar"><img src="../../static/images/avatar-2.jpg" alt=""></span>
                    <span class="name">Denise Jenny</span>
                    <span class="desc">Like your post: “Contact Form 7 Multi-Step”</span>
                    <span class="time">Oct, 28</span>
                </a>
            </li>
            <li>
                <a href="#">
                    <span class="avatar"><img src="../../static/images/avatar-sm-8.jpg" alt=""></span>
                    <span class="name">Thomas William</span>
                    <span class="desc">Like your post: “Facebook Messenger”</span>
                    <span class="time">Oct, 27</span>
                </a>
            </li>
        </ul>

        <a href="#" class="notice-read-more">See more messages <i class="fa fa-angle-down"></i></a>
    </div>

</div>


<div id="message-popup" class="notice-popup js__toggle" data-space="75">
    <h2 class="popup-title">Recent Messages<a href="#" class="pull-right text-danger">New message</a></h2>
    <!-- /.popup-title -->
    <div class="content">

    </div>

</div>


<div id="wrapper">
    <div class="main-content">
        <div class="row small-spacing">
            <div class="col-xs-12">
                <div class="box-content">
                    <h4 class="box-title">Default</h4>
                    <form class="form-inline" role="form" style="float:left;">
                        <div class="form-group has-feedback">
                            <div class="input-group input-group-sm">
                                <div class="input-group-addon" >订单状态</div>
                                <select type="text" class="form-control"  id="status"
                                        placeholder="请输入订单状态">
                                    <option >全部</option>
                                    <option >冻结</option>
                                    <option >正常</option>
                                </select>
                                <div class="input-group-addon">用户名称</div>
                                <input type="text" class="form-control" id="name"  placeholder="请输入用户名称"></input>
                            </div>
                        </div>
                        <button type="button"  class="btn btn-xs btn-warning" id="Select" ><i class="glyphicon glyphicon-search"></i> 查询</button>
                    </form>
                    <div style="float: right">
                        <button type="button" class="btn btn-success btn-rounded btn-xs waves-effect waves-light" data-toggle="modal" data-target="#boostrapModal-3">生成员工账号</button>
                    </div>

                    <table id="example" class="table table-striped table-bordered display" style="width:100%">
                        <thead>
                        <tr>
                            <th>编号</th>
                            <th>账号</th>
                            <th>手机号</th>
                            <th>状态</th>
                            <th>冻结</th>
                            <th>重置</th>
                        </tr>
                        </thead>

                        <tbody id="tbody1">
                        </tbody>
                        <tfoot>
                        <tr>
                            <td colspan="7" align="center">
                                <ul class="pagination" id="byPage">

                                </ul>
                            </td>
                        </tr>

                        </tfoot>
                    </table>
                </div>
                <!-- /.box-content -->
            </div>
        </div>
        <!-- /.row small-spacing -->
<!--        <footer class="footer">-->
<!--            <ul class="list-inline"  id="byPage">-->

<!--            </ul>-->
<!--        </footer>-->
    </div>
<!--     /.main-content -->
</div><!--/#wrapper -->


<div class="modal fade" id="boostrapModal-3" tabindex="-1" role="dialog" aria-labelledby="myModalLabel-2">
    <div class="modal-dialog modal-sm" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel-2">新增账户</h4>
            </div>

            <div class="input-group input-group-sm" style="padding-bottom: 5px">
                <span class="input-group-addon">用户姓名</span>
                <input type="text" class="form-control"  id="newName"  placeholder="请输入用户姓名"></input>
            </div>
            <div class="input-group input-group-sm" style="padding-bottom: 5px">
                <span class="input-group-addon">用户电话</span>
                <input type="text" class="form-control"  id="phone"  placeholder="请输入用户电话"></input>
            </div>
            <div class="input-group input-group-sm"  style="padding-bottom: 5px">
                <span class="input-group-addon">用户角色</span>
                <select type="text" class="form-control"  id="role"
                        placeholder="请选择角色"></select>
            </div>
            <div class="modal-footer">
                <button type="button" onclick="document.getElementById('newName').value=''" class="btn btn-xs btn-default btn-sm waves-effect waves-light" data-dismiss="modal">关闭</button>
                <button type="button" onclick="userSave()" class="btn btn-xs btn-primary btn-sm waves-effect waves-light">确认新增</button>
            </div>
        </div>
    </div>
</div>


<script src="../../static/scripts/jquery.min.js"></script>
<script src="../../static/scripts/modernizr.min.js"></script>
<script src="../../static/plugin/bootstrap/js/bootstrap.min.js"></script>
<script src="../../static/plugin/mCustomScrollbar/jquery.mCustomScrollbar.concat.min.js"></script>
<script src="../../static/plugin/nprogress/nprogress.js"></script>
<script src="../../static/plugin/sweet-alert/sweetalert.min.js"></script>
<script src="../../static/plugin/waves/waves.min.js"></script>

<!-- Data Tables -->
<script src="../../static/plugin/datatables/media/js/jquery.dataTables.min.js"></script>
<script src="../../static/plugin/datatables/media/js/dataTables.bootstrap.min.js"></script>
<script src="../../static/plugin/datatables/extensions/Responsive/js/dataTables.responsive.min.js"></script>
<script src="../../static/plugin/datatables/extensions/Responsive/js/responsive.bootstrap.min.js"></script>
<!--<script src="../../static/scripts/datatables.demo.min.js"></script>-->

<!--<script src="../../static/scripts/main.min.js"></script>-->
<script type="text/javascript">
    $(function () {


        $(document).ready(function () {
            $.ajax({
                url: "/role/findAll",
                success: function (data) {
                    var message = "<option>请选择角色</option>";
                    $.each(data.roleList, function (index, role) {
                        if (role.rname != "出租户" && role.rname != "抢租客") {
                        message += "<option value=" + role.rid + ">" + role.rname + "</option>";
                    }
                    });
                    $("#role").html(message);
                }
            });
        });



        $("#Select").click(function () {
            showByPage(1);
        });

        $(document).ready(function() {
            $("#page1").load("/menu");
        });
        showByPage(1);

    })

    function showByPage(pageNum){
        var status=$("#status").val();
        if(status=="全部"){
            status=null;
        }
        var acount=$("#name").val();
        var phone=$("#phone").val();
        $.ajax({
            url : "/user/findAll",
            type : "post",
            data:{
                "pageNum":pageNum,
                "status":status,
                "acount":acount,
                "phone":phone,

    },
            success : function(obj) {
                if (obj.result) {
                    var message = "";
                    $.each(obj.userList,
                        function(index,user) {
                            message += "<tr>";
                            message += "<td>"+(index+1)+"</td>";
                            message += "<td>"+user.acount+"</td>";
                            message += "<td>"+user.phone+"</td>";
                            message += "<td>"+user.status+"</td>";
                            // message += "<td>";
                            // if (user.status!=null){
                            //     if (user.status==="待审核") {
                            //         message += "<button type='button' class='btn btn-info  btn-rounded btn-xs waves-effect waves-light' onclick='statusBy(\""+user.uid+"\",\""+user.status+"\")'><i class='glyphicon glyphicon-ok'>通过</i></button>";
                            //         message += "<button type='button' class='btn btn-danger btn-rounded btn-xs  waves-effect waves-light' onclick='statusFail(\""+user.uid+"\",\""+user.status+"\")'><i class='glyphicon glyphicon-ban-circle'>未通过</i></button>";
                            //     }}
                            // message += "</td>";
                            message += "<td>";
                                if (user.status!=null){
                                    if (user.status==="正常") {
                                        message += "<button type='button' class='btn btn-violet btn-rounded btn-xs waves-effect waves-light' onclick='statusFreeze(\"" + user.uid + "\",\"" + user.status + "\")'><i class='glyphicon glyphicon-lock'>冻结</i></button>";
                                    }}
                            if (user.status!=null){
                              if (user.status==="冻结") {
                            message += "<button type='button' class='btn btn-warning btn-rounded btn-xs waves-effect waves-light' onclick='statusThaw(\""+user.uid+"\",\""+user.status+"\")'><i class='glyphicon glyphicon-log-in'>解冻</i></button>";
                                }}
                            message += "</td>";
                            message += "<td>";
                            if (user.role!=null){
                            if (user.role.rname==="平台"){
                            message += "<button type='button' class='btn btn-success btn-rounded  btn-xs waves-effect waves-light' onclick='Reset("+user.uid+")'><i class='glyphicon glyphicon-refresh'>重置</i></button>";
                            }
                            }
                            message += "</td>";
                            message += "</tr>";
                        });
                    $("#tbody1").html(message);

                    var pageMessage = "";
                    pageMessage +='<li class="'+(obj.pageInfo.pageNum==1?"disabled":"")+'"><a onclick="showByPage('+obj.pageInfo.prePage+')">上一页</a></li>';
                    for(var i=1;i<=obj.pageInfo.pages;i++){
                        pageMessage +='<li class="'+(obj.pageInfo.pageNum==i?"active":"")+'"><a onclick="showByPage('+i+')">'+i+' <span class="sr-only">(current)</span></a></li>';
                    }
                    pageMessage +='<li class="'+(obj.pageInfo.pageNum==obj.pageInfo.pages?"disabled":"")+'"><a onclick="showByPage('+obj.pageInfo.nextPage+')">下一页</a></li>';
                    $("#byPage").html(pageMessage);
                }

            }

        });
    }




     // 账号投诉过多，冻结改账号

    function statusFreeze(uid,status) {
        if (status=="正常"){
            var  status="冻结";
            $.ajax({
                url: "/user/updateAudit",
                type: "post",
                data: {
                    "status": status,
                    "uid":uid,
                },
                success: function (data) {
                        window.location.href = "/user/userList";
                }
            });
        }
    }


     // 解除账号冻结

    function statusThaw(uid,status) {
        if (status=="冻结"){
            var  status="正常";
            $.ajax({
                url: "/user/updateAudit",
                type: "post",
                data: {
                    "status": status,
                    "uid":uid,
                },
                success: function (data) {
                    window.location.href = "/user/userList";
                }
            });
        }
    }

    //重置密码
    function Reset(uid){
        $.ajax({
            url: "/user/resetPassword",
            type: "post",
            data: {
                "uid":uid,
            },
            success: function (data) {
                window.location.href = "/user/userList";
            }
        });
    }


    //新增账户
    function userSave() {
        $.ajax({
            url: "/user/saveUser",
            type: "post",
            data: {
                "acount": $("#newName").val(),
                "rid":$("#role").val(),
                "phone":$("phone").val(),
            },
            success: function (data) {
                window.location.href = "/user/userList";
            }
        });

    }



</script>
</body>
</html>